package org.uned.agonzalo16.bitacora.dao;

import static org.uned.agonzalo16.bitacora.dao.OfyFactory.ofy;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.uned.agonzalo16.bitacora.domain.Blog;
import org.uned.agonzalo16.bitacora.domain.BlogContribution;
import org.uned.agonzalo16.bitacora.domain.User;

@Repository
public class BlogContributionDao {

	public List<BlogContribution> findAll() {
		return ofy().load().type(BlogContribution.class).list();
	}

	public List<BlogContribution> findByBlog(Blog blog) {
		return ofy().load().type(BlogContribution.class).filter("blog", blog).list();
	}

	public List<BlogContribution> findByUser(User user) {
		return ofy().load().type(BlogContribution.class).filter("user", user).list();
	}

	public BlogContribution get(Long id) {
		return ofy().load().type(BlogContribution.class).id(id).now();
	}

	public BlogContribution merge(BlogContribution bc) {
		ofy().save().entity(bc).now();
		return bc;
	}

	public void delete(Long id) {
		ofy().delete().type(BlogContribution.class).id(id).now();
	}
}
